package com.miracle.film.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.miracle.film.domain.FlmFilmInfo;
import com.miracle.film.service.IFlmFilmInfoService;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电影信息Controller
 * 
 * @author miracle
 * @date 2022-07-27
 */
@RestController
@RequestMapping("/film/filmInfo")
public class FlmFilmInfoController extends BaseController
{
    @Autowired
    private IFlmFilmInfoService flmFilmInfoService;

    /**
     * 查询电影信息列表
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlmFilmInfo flmFilmInfo)
    {
        startPage();
        List<FlmFilmInfo> list = flmFilmInfoService.selectFlmFilmInfoList(flmFilmInfo);
        return getDataTable(list);
    }

    /**
     * 导出电影信息列表
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:export')")
    @Log(title = "电影信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlmFilmInfo flmFilmInfo)
    {
        List<FlmFilmInfo> list = flmFilmInfoService.selectFlmFilmInfoList(flmFilmInfo);
        ExcelUtil<FlmFilmInfo> util = new ExcelUtil<FlmFilmInfo>(FlmFilmInfo.class);
        util.exportExcel(response, list, "电影信息数据");
    }

    /**
     * 获取电影信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(flmFilmInfoService.selectFlmFilmInfoById(id));
    }

    /**
     * 新增电影信息
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:add')")
    @Log(title = "电影信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlmFilmInfo flmFilmInfo)
    {
        return toAjax(flmFilmInfoService.insertFlmFilmInfo(flmFilmInfo));
    }

    /**
     * 修改电影信息
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:edit')")
    @Log(title = "电影信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlmFilmInfo flmFilmInfo)
    {
        return toAjax(flmFilmInfoService.updateFlmFilmInfo(flmFilmInfo));
    }

    /**
     * 删除电影信息
     */
    @PreAuthorize("@ss.hasPermi('film:filmInfo:remove')")
    @Log(title = "电影信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(flmFilmInfoService.deleteFlmFilmInfoByIds(ids));
    }

    /**
     * 为首页查询电影信息
     */
    @Anonymous //允许不登录访问
    // @PreAuthorize("@ss.hasPermi('film:filmInfo:list4Index')")
    @GetMapping("/list4Index/")
    public AjaxResult list4Index(FlmFilmInfo flmFilmInfo)
    {
        AjaxResult ajax = AjaxResult.success();
        flmFilmInfo.setStatus("00");
        List<FlmFilmInfo> list = flmFilmInfoService.selectFlmFilmInfoList(flmFilmInfo);
        ajax.put("films", list);
        return ajax;
    }

}
